package cz.cvut.fel.taskpro.data.entity;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 * This entity represents User. There are three user type in system. Each extends
 * from this entity.
 * @author Tom
 * @version 1.0.0 beta
 */
@Entity
@Table(name = "taskProUser")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "role", discriminatorType = DiscriminatorType.STRING, length = 8)
@NamedQueries({
    @NamedQuery(name = "TaskProUser.findByLogin", query = "SELECT u FROM TaskProUser u WHERE u.login = :login"),
    @NamedQuery(name = "TaskProUser.findByEmail", query = "SELECT u FROM TaskProUser u WHERE u.email = :email"),
    @NamedQuery(name = "TaskProUser.all", query = "SELECT u FROM TaskProUser u")//,
//    @NamedQuery(name="TaskProUser.findByZadani", query="SELECT u FROM Uzavatel u")
})
public class TaskProUser implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue
    @Column(name = "id")
    private int id;
    @Column(name = "login", nullable = false, unique = true)
    private String login;
    @Column(name = "password", nullable = false, length=64)
    private String password;
    @Column(name = "name", nullable = false)
    private String name;
    @Column(name = "email", nullable = false, unique = true)
    private String email;
    @Column(name = "surname", nullable = false)
    private String surname;

    public TaskProUser() {
    }

    public String getPassword() {
        return password;
    }

    public String getName() {
        return name;
    }

    public int getId() {
        return id;
    }

    public String getLogin() {
        return login;
    }

    public String getEmail() {
        return email;
    }

    public String getSurname() {
        return surname;
    }

    public void setPassword(String newVal) {
        password =newVal;
    }

    public void setName(String newVal) {
        name = newVal;
    }

    public void setLogin(String newVal) {
      login=newVal;
    }

    public void setEmail(String newVal) {
        email = newVal;
    }

    public void setSurname(String newVal) {
        surname = newVal;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof TaskProUser)) {
            return false;
        }
        TaskProUser other = (TaskProUser) object;
        if (this.id != other.id) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (int) id;
        return hash;
    }

    @Override
    public String toString() {
        return "DL.entity.Uzivatel[ id=" + getId() + " login=" + getLogin() + " ]";
    }

}